﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Soundteller.Audio.Repositories;
using Soundteller.Audio.Repositories.Interfaces;
using Soundteller.Common.Tests;
using Moq;
using Soundteller.Audio.Model.Interfaces;

namespace Soundteller.Audio.Tests.Unit.Repositories.BeatRepositorySpecifications
{
    public abstract class WhenUpdate : TestBase
    {
        protected IBeatRepository BeatRepository { get; private set; }
        protected Mock<IMemoryContext> Context { get; private set; }
        protected double? UpdatedBeat { get; private set; }
        protected abstract double Beat { get; }

        protected override void Arrange()
        {
            Context = new Mock<IMemoryContext>();
            Context.SetupSet(c => c.CurrentBeat = It.IsAny<double?>()).Callback<double?>(b => UpdatedBeat = b);

            BeatRepository = new BeatRepository(Context.Object);
        }

        protected override void Act()
        {
            BeatRepository.Update(Beat);
        }
    }

    [TestClass]
    public class WhenUpdateGivenBeatIsZero : WhenUpdate
    {
        protected override double Beat
        {
            get { return 0; }
        }

        [TestMethod]
        public void ThenBeatShouldBeZero()
        {
            Assert.AreEqual(0, UpdatedBeat);
        }
    }

    [TestClass]
    public class WhenUpdateGivenBeatIsThirteen : WhenUpdate
    {
        protected override double Beat
        {
            get { return 13; }
        }

        [TestMethod]
        public void ThenBeatShouldBeThirteen()
        {
            Assert.AreEqual(13, UpdatedBeat);
        }
    }
}
